package com.jt.config;

import com.jt.vo.SysResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author: taoyi
 * @date: 2021/6/15 14:44
 * @version: 1.0
 * @explain: 全局异常处理配置类
 */
// 全局异常处理，返回值为JSON
@RestControllerAdvice //@ControllerAdvice + @ResponseBody
public class MyExceptionConfig {

    // 有异常时调用
    @ExceptionHandler(RuntimeException.class)
    public Object handler(Exception e){
        // 打印报错信息
        e.printStackTrace();
        return SysResult.fail();
    }
}
